package wc;


import java.io.*;
/**
 * Author: wuhen
 * Date: 2018/9/20
 * Time: 18:35
 */
public class BasicInfo {
    public static Wc basicInfo(String fileName)
    {
        Wc wc=new Wc();
        char charNow;
        try
        {
            File filename = new File(fileName);
            InputStreamReader reader = new InputStreamReader(
                    new FileInputStream(filename));
            BufferedReader br = new BufferedReader(reader);
            String line ;
            line = br.readLine();
            boolean partition=true;
            while (line != null)
            {

                wc.chars+=line.length();
                wc.lines++;


                for(int i=0;i<line.length();i++)
                {
                    charNow=line.charAt(i);
                    if(partition==true&&charNow!='/'&&charNow!='*'&&charNow!='{'&&charNow!='}'&&charNow!='c'&&charNow!='('&&charNow!=')'&&charNow!='\t'&&charNow!=','&&charNow!='.'&&charNow!='?')
                    {
                        wc.words++;
                    }
                    if(charNow==' '||charNow=='\t'||charNow==','||charNow==',')
                    {
                        partition=true;
                    }

                }
                line = br.readLine();
            }
            wc.chars+=wc.lines-1;
            br.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return wc;
    }
}
